<?php

//$link=  base_url()."assets/fpdf17/fpdf.php";
include('assets/fpdf17/fpdf.php');
$lib_rupiah = new Format_rupiah();
$totalsemua = 0;

class PDF extends FPDF {

    // Page header
    function Header() {
        // Logo
//        $this->SetFont('Arial', '', 12);
//        $this->Line(10, 22, 200, 22);
//        $this->Ln(17);
    }

}

$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();

$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(0, 0, 'LAPORAN TRANSAKSI PEMESANAN ', 0, 0, 'C');

$pdf->Ln(4);
$pdf->SetFont('Times', '', 8);

if ($date1 != "" and $date2 != "")
    $pdf->Cell(0, 0, $date1 . " s/d " . $date2, 0, 0, 'C');

//else if ($id == 2)
//    $pdf->Cell(0, 0, 'STATUS GAGAL', 0, 0, 'C');
//else if ($id == 3)
//    $pdf->Cell(0, 0, 'STATUS SUKSES', 0, 0, 'C');
//$pdf->Ln(4);


$pdf->SetFont('Times', '', 10);


$pdf->Ln(5);

foreach ($list as $pemesanan) {

    $pdf->SetFont('Times', '', 7);
    $pdf->SetFillColor(234, 234, 234);
    
    if ($pemesanan->status == 0)
        $status = "Proses";
    else if ($pemesanan->status == 1)
        $status = "Gagal";
    else if ($pemesanan->status == 2)
        $status = "Sukses";
    else 
        $status="";
    
    $pdf->Cell(0, 5, ' #Id : ' . $pemesanan->id . '       Tanggal : ' . $pemesanan->date . '     Total : ' . $lib_rupiah->rupiah($pemesanan->sub_total) . '     Biaya Kirim : ' . $lib_rupiah->rupiah($pemesanan->biaya_kirim) . '       Grand Total : ' . $lib_rupiah->rupiah($pemesanan->grand_total) . '       Status :  ' .$status, 'LRTB', 0, '', 1);
    $pdf->Ln();
    $pdf->SetFont('Times', '', 7);
    $pdf->SetFillColor(234, 234, 234);
    $pdf->Cell(10, 5, ' KODE  ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(80, 5, ' NAMA PRODUK ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(30, 5, ' SIZE ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(23, 5, ' HARGA ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(12, 5, ' BNY ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(12, 5, ' DISC ', 'LRTB', 0, 'C', 1);
    $pdf->Cell(23, 5, ' TOTAL ', 'LRTB', 0, 'C', 1);
    $pdf->Ln();

    $n = 0;
    foreach ($list_det as $indexs) {
        foreach ($indexs as $pemesanan_det) {
            if ($pemesanan_det->id_pemesanan == $pemesanan->id) {
                $pdf->Cell(10, 5, $pemesanan_det->id_produk_det, 'LRTB', 0, 'C');
                $pdf->Cell(80, 5, $pemesanan_det->nama_produk, 'LRTB', 0);
                $pdf->Cell(30, 5, $pemesanan_det->size_produk, 'LRTB', 0, 'C');
                $pdf->Cell(23, 5, $lib_rupiah->rupiah($pemesanan_det->harga), 'LRTB', 0, 'R');
                $pdf->Cell(12, 5, $pemesanan_det->bnyk, 'LRTB', 0, 'C');
                $pdf->Cell(12, 5, $pemesanan_det->disk . " %", 'LRTB', 0, 'C');
                $pdf->Cell(23, 5, $lib_rupiah->rupiah($pemesanan_det->sub_total), 'LRTB', 0, 'R');
                $pdf->Ln();
                $totalsemua = $totalsemua + $pemesanan_det->sub_total;
            }
        }
    }
    $pdf->Ln();
}
$pdf->SetFont('Times', 'B', 10);
$pdf->Cell(0, 0, 'Total Semua Transaksi : Rp. ' . $totalsemua, 0, 0, 'R');

$pdf->Output();
?>